
import { _decorator, Component, Prefab, tween, v3, director, Canvas } from 'cc';
const { ccclass, property } = _decorator;

export interface LayerCfg {
    bundleName: string
    prefabName: string
}

@ccclass('LayerBase')
export abstract class LayerBase extends Component {
    public closeCallback!: (ret: any) => void;
    abstract _ret: any
    abstract init(data: any): void
    public prefab!: Prefab

    onLoad() {
        const container = this.node.getChildByName('Container')
        if (container) {
            tween(container)
                .set({ scale: v3(1.3, 1.3, 1.3) })
                .to(0.1, { scale: v3(0.8, 0.8, 0.8) })
                .to(0.1, { scale: v3(1, 1, 1) })
                .start()
        }
    }

    close() {
        this.node.destroy()
        const prefab = this.prefab
        setTimeout(() => {
            prefab.decRef()
        }, 3 * 60 * 1000);
        this.closeCallback(this._ret)
    }
}
